#ifndef GAMEENGINE_GRAPHICS_WIDGET_GL_WIDGET_H
#define GAMEENGINE_GRAPHICS_WIDGET_GL_WIDGET_H

#include <GameEngine/Graphics/graphics_settings.h>

#include <GameEngine/Graphics/Scene/scene.h>
#include <GameEngine/Graphics/Camera/camera_manipulator_examine.h>
#include <GameEngine/Graphics/Camera/camera_manipulator_isometric.h>
#include <GameEngine/Core/Color/color_rgb.h>

#ifdef GAMEENGINE_SHOW_FPS
#ifdef _DEBUG
#include <GameEngine/Core/timer.h>
#endif
#endif

#pragma warning( push )
#pragma warning( disable : 4312 )
#include <QtOpenGL/QGLWidget>
#pragma warning( pop )

#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif

//! Widget that implements an OpenGL window
class _Graphics_decl GLWidget : public QGLWidget {
	Q_OBJECT

public:
	GLWidget(QWidget *parent = nil, QGLWidget *shareWidget = nil);
	~GLWidget();

	QSize minimumSizeHint() const;
	QSize sizeHint() const;
	void setClearColor(const ColorRGBA &color);

	const Scene& scene() const;
	Scene& scene();

	CameraManipulator* manipulator();
	const CameraManipulator* manipulator() const;

signals:
	//! Signal emitted when the widget is clicked
	void clicked();

protected slots:
	void callPaintGL();

protected:
	void initializeGL();
	void paintGL();
	void resizeGL(int width, int height);
	void mousePressEvent(QMouseEvent *event);
	void mouseMoveEvent(QMouseEvent *event);
	void mouseReleaseEvent(QMouseEvent *event);

protected:
	//! Background color
	ColorRGBA clearColor_;

	//! Last position of the mouse
	QPoint lastPos_;
	//! Test if mouse was released
	bool released_mouse_;

	//! The scene associated to the widget
	Scene scene_;
	//! The manipulator that allows to interact with the objects of the scene
	CameraManipulatorIsometric manipulator_;

#ifdef GAMEENGINE_SHOW_FPS
#ifdef _DEBUG
	//! Timer used to measure FPS
	Timer timer_;

	//! Previous second count on the timer
	Time::Seconds prev_;

	//! Number of frames since the last FPS display
	int nb_frames_;

	//! Maximum number of frames before FPS are shown
	int nb_frames_max_;
#endif
#endif
};

//========================================================

#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif

#endif
